import { get, post, put, del } from './index'

// 短信验证码相关
export const smsApi = {
	// 发送短信验证码
	sendCode: (phone) => {
		return post('/api/sms/sendCode', { phone })
	},
}

// 企业绑定相关
export const companyBindApi = {
	// 绑定运维单位
	bindYwdw: (data) => {
		return post('/api/user/bindYwdw', data)
	},

	// 获取污染源企业列表
	getPollutionSourceList: (params = {}) => {
		return post('/api/bizPollutionSourceInfo/listall', params)
	},

	// 获取已绑定的污染源信息
	getBoundPollutionInfo: () => {
		return post('/api/bizPollutionSourceInfo/getByBind', {})
	},

	// 解绑企业
	unbindCompany: (data) => {
		return post('/api/user/unbindYwdw', data)
	},
}

// 微信相关API
export const wechatApi = {
	// 获取手机号
	getPhoneNumber: (appId, data) => {
		return post(`/api/wechat/mini/${appId}/phone`, data)
	},

	// 微信登录
	login: (appId, code) => {
		return get(`/api/wechat/mini/${appId}/login?code=${code}`)
	},
}

// 企业信息相关
export const companyInfoApi = {
	// 获取企业详细信息
	getCompanyInfo: () => {
		return post('/api/bizPollutionSourceInfo/getByBind', {})
	},

	// 更新企业信息
	updateCompanyInfo: (data) => {
		return post('/api/bizPollutionSourceInfo/edit', data)
	},

	// 获取排污口信息
	getOutlets: (params) => {
		return get('/api/bizPollutionSourceInfo/outlets', params)
	},

	// 更新排污口信息
	updateOutlets: (data) => {
		return post('/api/bizPollutionSourceInfo/outlets/update', data)
	},
}

// 文件上传相关
export const fileUploadApi = {
	// 上传企业相关文件
	uploadCompanyFile: (formData, onProgress) => {
		return post('/api/upload/company', formData, {
			headers: {
				'Content-Type': 'multipart/form-data',
			},
			onUploadProgress: onProgress,
		})
	},

	// 删除文件
	deleteFile: (fileId) => {
		return del(`/api/upload/file/${fileId}`)
	},

	// 下载文件模板
	downloadTemplate: (templateType) => {
		return get(`/api/template/download/${templateType}`, {
			responseType: 'blob',
		})
	},
}

export default {
	smsApi,
	companyBindApi,
	wechatApi,
	companyInfoApi,
	fileUploadApi,
}
